package com.mmy.controller.ship;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.mmy.controller.Common;
import com.mmy.controller.UtilConstants;
import com.mmy.domain.ship.TShipBase;
import com.mmy.domain.ship.TShipOrder;
import com.mmy.domain.ship.TShipPlan;
import com.mmy.domain.ship.VShipBase;
import com.mmy.domain.sys.TSysUser;
import com.mmy.service.ship.impl.ShipOrderServiceImpl;
import com.mmy.service.ship.impl.ShipPlanServiceImpl;
import com.mmy.service.ship.impl.TShipBaseServiceImpl;
import com.mmy.service.ship.impl.TShipOrderServiceImpl;
import com.mmy.service.ship.impl.TShipPlanServiceImpl;

@Controller
public class ShipFrontController {
	
	@Autowired
	TShipOrderServiceImpl tShipOrderServiceImpl;
	@Autowired
	TShipBaseServiceImpl tShipBaseServiceImpl;
	@Autowired
	TShipPlanServiceImpl tShipPlanServiceImpl;
	@Autowired
	ShipOrderServiceImpl shipOrderServiceImpl;
	@Autowired
	ShipPlanServiceImpl shipPlanServiceImpl;
	@Autowired
	Common common;
	
	/**
	 * 函数功能说明： 跳转--邮轮首页
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 
	 * @author 创建人 shangzl
	 * @date 创建日期
	 */
	@RequestMapping(value = "/shipindexfront")
	public String ToShipBase(Model model) {

		List<VShipBase> lstShipBase = tShipBaseServiceImpl.findAll();
		model.addAttribute("shipBase", lstShipBase);
		return "ship/shipindex";
	}
	
	/**
	 * 函数功能说明： 跳转--邮轮详情页
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 
	 * @author 创建人 shangzl
	 * @date 创建日期
	 */
	@RequestMapping(value = "/shipinfofront")
	public String shipinfo(Model model,HttpServletRequest request) {
		
		int iShipID = Integer.parseInt(request.getParameter("iShipID"));
		TShipBase shipBase = tShipBaseServiceImpl.findByShipID(iShipID);
		model.addAttribute("shipBase", shipBase);
		return "ship/shipinfo";
	}
	
	/**
	 * 函数功能说明： 提交--邮轮预留
	 *
	 * @param 参数说明
	 * @return 返回值说明 jsp页面
	 * @throws 
	 * @author 创建人 liys
	 * @date 创建日期 2021.03.08
	 */
	@RequestMapping(value = "/subreserveshipbase")
	public String ReserveShipBase(TShipOrder tShipOrder, HttpSession session, String PlanID, String ShipID){

		tShipOrder.setID(common.createMaxID(UtilConstants.TableName.T_SHIP_ORDER));
		int iPlanID = Integer.parseInt(PlanID);
		String cOrderID = common.createOrderCode(UtilConstants.TableName.T_SHIP_ORDER, iPlanID);
		TShipPlan tShipPlan = tShipPlanServiceImpl.findByPlanID(iPlanID);
		tShipOrder.setCreateDate(new Date());
		tShipOrder.setReserveDate(new Date());
		tShipOrder.setFloor(tShipPlan.getFloor());
		tShipOrder.setPeer(tShipPlan.getPeer());
		tShipOrder.setPrice(tShipPlan.getPrice());
		BigDecimal bPrice = tShipPlan.getPrice();
		tShipOrder.setOrderAmount(bPrice);
		TSysUser tSysUser = (TSysUser) session.getAttribute("tSysUser");
		tShipOrder.setCreator(tSysUser.getUserName());
		tShipOrder.setReserveUserID(tSysUser.getUserID());
		tShipOrder.setOrderID(cOrderID);
		tShipOrderServiceImpl.save(tShipOrder.getID());
		tShipOrder.setOrderState((byte) 0);
		tShipOrder.setCashierState((byte) 0);
		tShipOrder.setAccountState((byte) 0);
		tShipOrder.setInvoiceState((byte) 0);
		tShipOrder.setRefundState((byte) 0);
		tShipOrder.setRemittanceState((byte) 0);
		tShipOrderServiceImpl.save(tShipOrder);
		return "redirect:shipindexfront";
	}
}
